package com.ilxqx.framework.generator.cast;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * mysql类型转Java类型
 * @author venus
 */
public class MysqlTypeToJavaType implements CastToJavaType {

    /**
     * 将SQL类型转为Java类型
     *
     * @param type SQL类型
     * @return Java类型
     */
    @Override
    public Class<?> cast(String type) {
        switch (type) {
            // 整数类型
            case "int":
            case "integer":
            case "smallint":
            case "tinyint":
            case "mediumint":
                return Integer.class;
            case "bigint":
                return Long.class;

            case "float":
            case "double":
                return Double.class;

            case "decimal":
                return BigDecimal.class;

            case "datetime":
            case "timestamp":
                return LocalDateTime.class;

            case "date":
                return LocalDate.class;

            // 字符串类型
            case "char":
            case "varchar":
            case "text":
            case "tinytext":
            case "mediumtext":
            case "longtext":
            case "tinyblob":
            case "blob":
            case "mediumblob":
            case "longblob":
            default:
                return String.class;
        }
    }

}
